import Vue from 'vue'
import store from '@/store';

let Params = {}
Params.install = function (Vue, options) {

  Vue.getOneParams = Vue.prototype.$getOneParams = function () {
    let arr = []
    store.state.params.params.forEach(item => {
      arr.push({label: item.name, value: item.name})
    })
    return arr
  }

  Vue.getTwoParams = Vue.prototype.$getTwoParams = function (oneName) {
    let arr = []
    let index = store.state.params.params.findIndex((value, index, arr) => {
      return value.name === oneName
    })
    if (index !== -1) {
      store.state.params.params[index].f_paramvalues.forEach(item => {
        arr.push({label: item.name, value: item.name})
      })
    }
    return arr
  }

  Vue.getParams = Vue.prototype.$getParams = function (key) {
    let arr = []
    store.state.params.params.forEach(item => {
      if (item.name === key) {
        item.f_paramvalues.forEach(item => {
          arr.push({label: item.name, value: item.name})
        })
      }
    })
    return arr
  }

}

export default Params
